const mongoose = require('mongoose')
const Joi = require('joi');
const parkSchema = new mongoose.Schema({
    park_number: {
        type: String,
        required: [true, "未输入车位编号"],
    },
    area: {
        type: String,
        enum: ['A', 'B', 'C', 'D'],
    },
    position: {
        type: Number,
        required: [true, "未输入车位位置"],
        min: [1, "车位位置不合法"],
        max: [100, "车位位置不合法"],
    },
    isCar: {
        type: Boolean,
        default: false
    },
});

const JoiSchema = Joi.object({
    park_number: Joi.string().required().error(new Error("未输入车位编号")),
    area: Joi.string().error(new Error("停车位区域不合法")),
    position: Joi.number().min(1).max(100).required().error(new Error("车位位置不合法")),
    isCar: Joi.boolean().required(),
});

const Park = mongoose.model("Park", parkSchema);
// const test = new Park({
//     area: "A",
//     position: "1",
//     isCar: true,
//     car_id: null
// });
// test.save();

module.exports = Park;